<?php
/**
 * 用户表数据操作层
 * @author yangchao
 * @package user
 * @copyright yangchao
 * @version 1.0
 * @code-encode utf-8
 * @data-encode 2011-01-17
 */

class db_user_info extends db_base {
    
	var $table_name = "user_info";
	
	function db_user_info()
	{
		parent::db_base();
	}
	
	/**
	 * 前台取用户信息
	 * @param $uid
	 */
	function get_user_info_item_by_uid($uid)
	{
		$mc = mem_cache::get_instance();
		$key = CACHE_PREFIX_USER_ITEM;
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$content = $this->get_alllist($this->table_name,1,1,"","uid='{$uid}' and status=1");
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_TIME_USER_ITEM);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content[0];
		
	}
	
	
	//前台取用户信息（包括已删除）
	function get_user_info_item_by_uid_with_del($uid)
	{
		
	}
	
	/**
	 * 根据用户名取数据
	 * @param $user_name
	 * @param $password
	 */
	function get_user_item_by_name($user_name)
	{
		
		$mc = mem_cache::get_instance();
		$key = CACHE_PREFIX_USER_ITEM;
		$cache = $mc->get($key);
		if ($cache === false)
		{
			$where = "user_name ='{$user_name}' and status = 1";
			$content = $this->get_alllist($this->table_name,1,1,"",$where);
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_TIME_USER_ITEM);
		}
		else
		{
			$content = unserialize($cache);
		}
		return $content ? $content[0] : false;
	}
	
	
	/**
	 * 用户注册
	 * @param $user_name
	 * @param $password
	 */
	function insert_user_info($user_name,$password)
	{
		// 插入数据
		$ary = array();

		$ary["user_name"] = $user_name;
		$ary["password"] = $password;
		$ary["user_nickname"] = $user_name;

		$ary["create_time"] = Date::get_date_time();
		$ary["create_ip"] = IP::get_client_ip_long();
		$ary["update_time"] = Date::get_date_time();
		$ary["update_ip"] = IP::get_client_ip_long();
		$ary["status"] = 1;
		
		$ret = $this->insert($this->table_name, $ary);
		if ($ret)
		{
			/*$memcache = mem_cache::get_instance();
			$memcache->delete($key);*/
		}
		else
		{
			return false;
		}


		return $ret;
	}
	
	

}


?>
